﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Data;
using VietKinsNutrition.Data;

namespace VietKinsNutrition.Bussiness
{
    public class ClsTblMonan_ThucphamBLL : ClsBindingBLL
    {
        public ClsTblMonan_ThucphamBLL(DataTable tbl)
        {
            ReturnTbl = tbl;
        }
        private DataTable ReturnTbl;
        ClsTblDm_Nhomthucpham_ThucanDAL ClsTblDm_Nhomthucpham_Thucandal = new ClsTblDm_Nhomthucpham_ThucanDAL();
        public void Bind_Nhomthucpham_ThucanCbo(ComboBox Cbo)
        {
            Cbo.DataSource = this.ClsTblDm_Nhomthucpham_Thucandal.SelectAll();
            Cbo.ValueMember = "Id";
            Cbo.DisplayMember = "Tennhom";
        }
        public void Bind_Nhomthucpham_ThucanCboAdALL(ComboBox Cbo)
        {
            DataSet Set = (DataSet)this.ClsTblDm_Nhomthucpham_Thucandal.SelectAll().DataSource;
            DataRow New = Set.Tables[0].NewRow();
            New["Id"] = -1;
            New["Tennhom"] = "-Tất cả-";
            Set.Tables[0].Rows.InsertAt(New, 0);
            Cbo.DataSource = Set.Tables[0];
            Cbo.ValueMember = "Id";
            Cbo.DisplayMember = "Tennhom";
        }

        public void Bind_GridThucpham_thucan(int Nhomthucpham_ThucanId, DataGridView Grid)
        {
            ClsTblDm_NhapthucphamDAL ClsTblDm_Nhapthucphamdal = new ClsTblDm_NhapthucphamDAL();
            DataTable NewTbl;
            NewTbl = ClsTblDm_Nhapthucphamdal.GetTable(Nhomthucpham_ThucanId);
            DataTable Tbl = new DataTable();
            Tbl.Columns.Add("STT");
            Tbl.Columns.Add("Id");
            Tbl.Columns.Add("Tenthucan");
            Tbl.Columns.Add("Tendonvitinh");
            if (NewTbl.Rows.Count > 0)
            {
                foreach (DataRow Row in NewTbl.Rows)
                {
                    Tbl.Rows.Add(Row["STT"], Row["Id"], Row["Tenthucan"], Row["Tendonvitinh"]);
                }
            }
            Grid.DataSource = Tbl;
        }

        public DataTable TblMonan_Thucpham(string Trangthai, int ListId, int Thucpham_ThucanId, int ThuvienmonanId, string ListTenthucan, string Soluong, string ListTendonvitinh)
        {
            ClsTblMonan_ThucphamDAL ClsTblMonan_Thucphamdal = new ClsTblMonan_ThucphamDAL(ReturnTbl);
            return ClsTblMonan_Thucphamdal.TblMonan_Thucpham(Trangthai, ListId, Thucpham_ThucanId, ThuvienmonanId, ListTenthucan, Soluong, ListTendonvitinh);
        }


        public void Insert(int Thucpham_ThucanId, int ThuvienmonanId, string Soluong)
        {
            ClsTblMonan_ThucphamDAL ClsTblMonan_Thucphamdal = new ClsTblMonan_ThucphamDAL(ReturnTbl);
            ClsTblMonan_Thucphamdal.Insert(Thucpham_ThucanId, ThuvienmonanId, Soluong);
        }
        public void Delete(int ThuvienmonanId)
        {
            ClsTblMonan_ThucphamDAL ClsTblMonan_Thucphamdal = new ClsTblMonan_ThucphamDAL(ReturnTbl);
            ClsTblMonan_Thucphamdal.Delete(ThuvienmonanId);
        }
        public DataSet SelectByThuvienmonanId(int ThuvienmonanId)
        {
            ClsTblMonan_ThucphamDAL ClsTblMonan_Thucphamdal = new ClsTblMonan_ThucphamDAL(ReturnTbl);
            return ClsTblMonan_Thucphamdal.SelectByThuvienmonanId(ThuvienmonanId);
        }
    }
}
